#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：pythonProject2 
@File    ：client-new.py
@Author  ：beibei
@Date    ：2023/12/22 4:59 PM 
'''
import socket
import time

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ("127.0.0.1", 8991)
client_socket.connect(server_address)

try:
    # 推送消息 'abc'
    client_socket.sendall('push\ndata: abc'.encode('utf-8'))
    response = client_socket.recv(1024).decode('utf-8')
    print(response)

    time.sleep(1)

    # 推送消息 'qwe'
    client_socket.sendall('push\ndata: qwe'.encode('utf-8'))
    response = client_socket.recv(1024).decode('utf-8')
    print(response)

    time.sleep(1)

    # 拉取消息
    client_socket.sendall('pull'.encode('utf-8'))
    response = client_socket.recv(1024).decode('utf-8')
    print(response)

    time.sleep(1)

    # 再次拉取消息
    client_socket.sendall('pull'.encode('utf-8'))
    response = client_socket.recv(1024).decode('utf-8')
    print(response)

    time.sleep(1)

    # 关闭连接
    client_socket.sendall('close'.encode('utf-8'))

except ConnectionAbortedError:
    print('会话被断开')

